home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / smburi.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  3KB  |  95 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import urllib
  5.  
  6. def _urlquote(x):
  7.     q = urllib.quote(x)
  8.     for c in [
  9.         '/',
  10.         '@',
  11.         ':']:
  12.         q = q.replace(c, '%%%02X' % ord(c))
  13.     
  14.     return q
  15.  
  16.  
  17. class SMBURI:
  18.     
  19.     def __init__(self, uri = None, group = '', host = '', share = '', user = '', password = ''):
  20.         if uri:
  21.             if group and host and share and user or password:
  22.                 raise RuntimeError
  23.             password
  24.             if uri.startswith('smb://'):
  25.                 uri = uri[6:]
  26.             
  27.             self.uri = uri
  28.         else:
  29.             self.uri = self._construct(group, host, share, user = user, password = password)
  30.  
  31.     
  32.     def _construct(self, group, host, share, user = '', password = ''):
  33.         uri_password = ''
  34.         if password:
  35.             uri_password = ':' + _urlquote(password)
  36.         
  37.         if user:
  38.             uri_password += '@'
  39.         
  40.         uri = '%s%s%s' % (_urlquote(user), uri_password, _urlquote(group))
  41.         if len(group) > 0:
  42.             uri += '/'
  43.         
  44.         uri += _urlquote(host)
  45.         if len(share) > 0:
  46.             uri += '/' + _urlquote(share)
  47.         
  48.         return uri
  49.  
  50.     
  51.     def get_uri(self):
  52.         return self.uri
  53.  
  54.     
  55.     def sanitize_uri(self):
  56.         (group, host, share, user, password) = self.separate()
  57.         return self._construct(group, host, share)
  58.  
  59.     
  60.     def separate(self):
  61.         uri = self.get_uri()
  62.         user = ''
  63.         password = ''
  64.         auth = uri.find('@')
  65.         if auth != -1:
  66.             u = uri[:auth].find(':')
  67.             if u != -1:
  68.                 user = uri[:u]
  69.                 password = uri[u + 1:auth]
  70.             else:
  71.                 user = uri[:auth]
  72.             uri = uri[auth + 1:]
  73.         
  74.         sep = uri.count('/')
  75.         group = ''
  76.         if sep == 2:
  77.             g = uri.find('/')
  78.             group = uri[:g]
  79.             uri = uri[g + 1:]
  80.         
  81.         if sep < 1:
  82.             host = ''
  83.         else:
  84.             h = uri.find('/')
  85.             host = uri[:h]
  86.             uri = uri[h + 1:]
  87.             p = host.find(':')
  88.             if p != -1:
  89.                 host = host[:p]
  90.             
  91.         share = uri
  92.         return (urllib.unquote(group), urllib.unquote(host), urllib.unquote(share), urllib.unquote(user), urllib.unquote(password))
  93.  
  94.  
  95.